﻿using System;
using System.Web.Security;
using System.Web.UI.WebControls;
using InternetShop.Code;
using System.Web.Profile;

namespace InternetShop.Account
{
    public partial class Register : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            RegisterUser.ContinueDestinationPageUrl = Request.QueryString["ReturnUrl"];
        }

        protected void RegisterUser_CreatedUser(object sender, EventArgs e)
        {
            FormsAuthentication.SetAuthCookie(RegisterUser.UserName, false /* createPersistentCookie */);
            TextBox tbPhone = (TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Phone");
            TextBox tbUserName = (TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("UserName");
            TextBox tbAddress = (TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Address");
            TextBox tbName = (TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Name");
            TextBox tbSurname = (TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Surname");
            ProfileBase profile = ProfileBase.Create(tbUserName.Text, true);
            profile["Phone"] = tbPhone.Text;
            profile["Name"] = tbName.Text;
            profile["Surname"] = tbSurname.Text;
            profile["Address"] = tbAddress.Text;
            string continueUrl = RegisterUser.ContinueDestinationPageUrl;
            if (String.IsNullOrEmpty(continueUrl))
            {   
                continueUrl = "~/";
            }
            profile.Save();
            Response.Redirect(continueUrl);
        }

    }
}
